<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<!DOCTYPE html>
<html>
<head>
	<title>用户登录</title>
	<meta name="viewport" content="width=device-width, initial-scale=1">
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
	<link type="text/css" rel="stylesheet" href="./css/bootstrap.css">
	<link type="text/css" rel="stylesheet" href="./css/style.css">
	<script type="text/javascript" src="./js/jquery.min.js"></script>
	<script type="text/javascript" src="./js/bootstrap.min.js"></script>
	<script type="text/javascript" src="./js/simpleCart.min.js"></script>
	<script type="text/javascript" src="./js/sha1.js"></script>
</head>
<body>
	<!--header-->
	<jsp:include page="header.jsp">
		<jsp:param name="flag" value="9"></jsp:param>
	</jsp:include>
	<!--//header-->
	<!--account-->
	<div class="account">
		<div class="container">
			<div class="register">
				<c:if test="${!empty msg }">
					<div class="alert alert-success">${msg }</div>
				</c:if>
				<c:if test="${!empty failMsg }">
					<div class="alert alert-danger">${failMsg }</div>
				</c:if>

				<form action="./user_login" method="post">
					<div class="register-top-grid">
						<h3>用户登录</h3>
						<div class="input">
							<span>用户名<label style="color:red;">*</label></span>
							<input type="text" id="userName" name="userName" placeholder="请输入用户名" required="required">
						</div>
						<div class="input">
							<span>密码 <label style="color:red;">*</label></span>
							<input type="password" id="password" name="password" placeholder="请输入密码" required="required">
						</div>

						<div class="clearfix"> </div>
					</div>
					<div class="register-but text-center">
						<input type="button" value="提交" onclick="login()">
						<div class="clearfix"> </div>
					</div>
				</form>
				<div class="clearfix"> </div>
			</div>
	    </div>
	</div>
	<!--//account-->
	<!--footer-->
	<jsp:include page="./footer.jsp"></jsp:include>
	<!--//footer-->
</body>
<script type="text/javascript">
$(function(){
    $("#userName").textbox("setValue","admin");
    $("#password").textbox("setValue","admin");
    $("#w").window();
});

function login(){
    var userName = $("#userName").val();
    var password = hex_sha1($("#password").val());
    $.ajax({
        type: "post",
        url: "./loginController/loginUser",
        data: JSON.stringify( {
            userName:userName,
            password:password
        }),
        dataType: 'json',
        contentType:"application/json;charset=UTF-8",
        success: function(data, textStatus) {
            if (data.success) {
                //var token = data.token;
                //window.localStorage.setItem("mytoken",token);
                window.location="./index";
            }else{
                $.messager.alert("错误","登录失败！","error");
            }
        },
        complete : function(XMLHttpRequest, textStatus) {
        },
        error : function(XMLHttpRequest,textStatus,errorThrown) {
            //alert("Error:"+textStatus);
            //alert(errorThrown.toString());
            $.messager.alert("错误","登录错误！","error");
        }
    });
}

</script>
</html>